package lock.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.PatternSyntaxException;

/**
 * @author Brook
 * lock不会像synchronized一样异常的时候自动释放锁，
 * 所以最佳实践时finally中释放锁，以便保证发生异常的时候锁一定被释放
 *
 */
public class MustUnlock {
    private static Lock lock = new ReentrantLock();


    public static void main(String[] args) {
        lock.lock();
        try{
            System.out.println(Thread.currentThread().getName()+"start execute");
        }finally {
            lock.unlock();
        }
    }
}
